<?php

use yii\db\Migration;

class m210222_082633_merchant_settle_account extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%merchant_settle_account}}', [
            'id' => "int(10) unsigned NOT NULL AUTO_INCREMENT",
            'merchant_id' => "int(11) NOT NULL DEFAULT '0' COMMENT '企业ID'",
            'serial_number' => "varchar(50) NULL DEFAULT '' COMMENT '结算编号'",
            'product_pay_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实付金额'",
            'refund_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '退款金额'",
            'merchant_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商户金额'",
            'platform_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台金额'",
            'settlement_amount' => "decimal(10,2) NULL DEFAULT '0.00' COMMENT '结算金额'",
            'agent_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '代理商佣金'",
            'merchant_distribution_money' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商户分销佣金'",
            'start_time' => "int(10) unsigned NULL DEFAULT '0' COMMENT '开始时间'",
            'end_time' => "int(10) unsigned NULL DEFAULT '0' COMMENT '结束时间'",
            'created_at' => "int(10) unsigned NULL DEFAULT '0' COMMENT '创建时间'",
            'updated_at' => "int(10) unsigned NULL DEFAULT '0' COMMENT '更新时间'",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='企业针对订单的金额分配'");
        
        /* 索引设置 */
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%merchant_settle_account}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

